Install libraries for use to examine data using tidyverse this only has to be done one time and a # can be put in front of the code to comment it out so it does not run in the future as now.
# install.packages("tidyverse")
# install.packages("readxl")
# install.packages("janitor")
# install.packages("lubridate")
# install.packages("broom")
# install.packages("patchwork")
# install.packages("plotly")
Load the libraries each time you run a script or program
library(tidyverse) # loads a lot of libraries in this one to add more functionality
Registered S3 method overwritten by 'dplyr':
method from
print.rowwise_df
Registered S3 methods overwritten by 'dbplyr':
method from
print.tbl_lazy
print.tbl_sql
[30m── [1mAttaching packages[22m ───────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──[39m
[30m[32m✓[30m [34mggplot2[30m 3.2.1 [32m✓[30m [34mpurrr [30m 0.3.3
[32m✓[30m [34mtibble [30m 2.1.3 [32m✓[30m [34mdplyr [30m 0.8.3
[32m✓[30m [34mtidyr [30m 1.0.0 [32m✓[30m [34mstringr[30m 1.4.0
[32m✓[30m [34mreadr [30m 1.3.1 [32m✓[30m [34mforcats[30m 0.4.0[39m
[30m── [1mConflicts[22m ──────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
[31mx[30m [34mdplyr[30m::[32mfilter()[30m masks [34mstats[30m::filter()
[31mx[30m [34mdplyr[30m::[32mlag()[30m masks [34mstats[30m::lag()[39m
library(readxl) # allows you to read in excel files
library(janitor) # cleans up column names and removes empty columns if wanted
Attaching package: ‘janitor’
The following objects are masked from ‘package:stats’:
chisq.test, fisher.test
library(lubridate) # allows easy conversion of varaibles to date format
Attaching package: ‘lubridate’
The following object is masked from ‘package:base’:
date
library(broom) # cleans up output for easy presentation
library(scales) # works with the x and y scales on the plots
Attaching package: ‘scales’
The following object is masked from ‘package:purrr’:
discard
The following object is masked from ‘package:readr’:
col_factor
library(patchwork) # allows you to plot several graphs on one page
library(plotly)
Registered S3 method overwritten by 'data.table':
method from
print.data.table
Registered S3 methods overwritten by 'htmltools':
method from
print.html tools:rstudio
print.shiny.tag tools:rstudio
print.shiny.tag.list tools:rstudio
Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
Attaching package: ‘plotly’
The following object is masked from ‘package:ggplot2’:
last_plot
The following object is masked from ‘package:stats’:
filter
The following object is masked from ‘package:graphics’:
layout
options(scipen=999)
Recent global temperatures
global_temp.df <- read_excel("../data/climate_change_module_dataset.xls",
sheet = "Global Temperature",
skip=4)
Global CO2
loa_co2.df <- read_excel("../data/climate_change_module_dataset.xls",
sheet = "Mauna Loa CO2",
skip=4)
Vostock temperatures
vostok_temp.df <- read_excel("../data/climate_change_module_dataset.xls",
sheet = "Vostok Temp",
skip=4)
Vostock CO2
vostok_co2.df <- read_excel("../data/climate_change_module_dataset.xls",
sheet = "Vostok CO2",
skip=4)
Note this uses a different approach to explore the data The graph will be interactive
global_temp.plot <- global_temp.df %>%
ggplot(aes(year, temp_c)) +
geom_line()+
geom_point()
# global_temp.plot
ggplotly(global_temp.plot)
# Enter the years here
min_year_global = 1976
max_year_global = 1998
global_temp.df %>%
filter(year >= min_year_global & year <= max_year_global) %>%
summarize(time_difference_years = max_year_global - min_year_global,
min_temp_c = min(temp_c, na.rm=TRUE),
max_temp_c = max(temp_c, na.rm=TRUE))
global_temp.plot <- global_temp.df %>%
filter(year >= min_year_global & year <= max_year_global) %>%
ggplot(aes(year, temp_c)) +
geom_line()+
geom_point()
# global_temp.plot
ggplotly(global_temp.plot)
vostok_temp.plot <- vostok_temp.df %>%
ggplot(aes(ice_age_year_bp, temp_c)) +
geom_line()+
geom_point() +
scale_x_continuous(label=comma)
# vostok_temp.plot
ggplotly(vostok_temp.plot)
# Enter the years here
min_year_vostok = 231979
max_year_vostok = 237643
vostok_temp.df %>%
filter(ice_age_year_bp >= min_year_vostok & ice_age_year_bp <= max_year_vostok) %>%
summarize(time_difference_years = max_year_vostok - min_year_vostok,
min_temp_c = min(temp_c, na.rm=TRUE),
max_temp_c = max(temp_c, na.rm=TRUE))
# plot of temp over time for sub area
vostok_temp.plot <- vostok_temp.df %>%
filter(ice_age_year_bp >= min_year_vostok & ice_age_year_bp <= max_year_vostok) %>%
ggplot(aes(ice_age_year_bp, temp_c)) +
geom_line()+
geom_point()
# vostok_temp.plot
ggplotly(vostok_temp.plot)
NA